package cn.edu360.dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import cn.edu360.bean.UserBean;
import cn.edu360.dao.UserDao;
import cn.edu360.util.DBUtil;

public class UserDaoImpl implements UserDao {
     //保存字段
	public boolean save(UserBean user) {
		QueryRunner runner = DBUtil.getRunner();
		String sql = " insert into user values (?,?,?,?,?)";
		try {
			runner.update(sql, null, user.getName(), user.getPwd(), user.getAge(), user.getPnum());
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
    //字段查询
	public UserBean getUserByname(String name) {
		QueryRunner runner = DBUtil.getRunner();
		String sql = "select * from user where name=?";
		try {
			UserBean query = runner.query(sql, new BeanHandler<UserBean>(UserBean.class), name);
			return query;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
